package com.zs4sdk.statistics;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.common.library.util.ActivityHelper;
import com.reyun.tracking.sdk.Tracking;
import com.zs4gamesdk.R;
import com.zs4sdk.common.Zs4GameSharePreferences;

/**
 * Created by Administrator on 2018/4/28.
 */

 class ReYunTracking {
    public static final String RE_YUN_APP_KEY = "9b6ee793cd7d4e7553f94a6f988acda8";
    public static String getDeviceId(){
        String deviceId =  Tracking.getDeviceId();
        return deviceId;
    }

    public static void setRegisterWithAccountID(String accountId){
        Tracking.setRegisterWithAccountID(accountId);
    }

    public static void setLoginSuccessBusiness(String accountId){
        Tracking.setLoginSuccessBusiness(accountId);
    }

    public static void initWithKeyAndChannelId(Context context){
        String appkey =readReYunAppKey(context);
        if(appkey == null){
            ActivityHelper.showLongToast(context,context.getString(R.string.zs4Game_right_reyun_appkey));
            appkey = RE_YUN_APP_KEY;
        }
        Tracking.initWithKeyAndChannelId(context.getApplicationContext(),appkey,"_default_");
        String deviceId =  Tracking.getDeviceId();
        Log.e("device"," deviceid is "+deviceId);
    }
    public static void initWithKeyAndChannelId(Context context,String appKey){
        Tracking.initWithKeyAndChannelId(context.getApplicationContext(),appKey,"_default_");
    }
    public static void exitSdk(){
        Tracking.exitSdk();
    }
    private static String readReYunAppKey(Context context) {
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            if (appInfo != null) {
                return appInfo.metaData.getString("com.zs4game.reyun.appkey");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
